<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>SFML - Simple and Fast Multimedia Library</title>
        <meta http-equiv="Content-Type" content="text/html;"/>
        <meta charset="utf-8"/>
        <!--<link rel='stylesheet' type='text/css' href="https://fonts.googleapis.com/css?family=Ubuntu:400,700,400italic"/>-->
        <link rel="stylesheet" type="text/css" href="doxygen.css" title="default" media="screen,print" />
        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript" src="dynsections.js"></script>
        <link rel="stylesheet" type="text/css" href="search/search.css" />
        <link rel="stylesheet" type="text/css" href="searchOverrides.css" />
        <script type="text/javascript" src="search/searchdata.js"></script>
        <script type="text/javascript" src="search/search.js"></script>
        <script type="text/javascript">
        /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
          $(document).ready(function() { init_search(); });
        /* @license-end */
        </script>
    </head>
    <body>
        <div id="banner-container">
            <div id="banner">
                <span id="sfml">SFML 2.6.1</span>
            </div>
        </div>
        <div id="content">
<!-- Generated by Doxygen 1.9.7 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <span id="MSearchSelect"                onmouseover="return searchBox.OnSearchSelectShow()"                onmouseout="return searchBox.OnSearchSelectHide()">&#160;</span>
          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.svg" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="classes.html"><span>Class&#160;Index</span></a></li>
      <li><a href="hierarchy.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><b>sf</b></li><li class="navelem"><a class="el" href="classsf_1_1TcpSocket.html">TcpSocket</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#nested-classes">Classes</a> &#124;
<a href="#pub-types">Public Types</a> &#124;
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="#pro-types">Protected Types</a> &#124;
<a href="#pro-methods">Protected Member Functions</a> &#124;
<a href="#friends">Friends</a> &#124;
<a href="classsf_1_1TcpSocket-members.html">List of all members</a>  </div>
  <div class="headertitle"><div class="title">sf::TcpSocket Class Reference<div class="ingroups"><a class="el" href="group__network.html">Network module</a></div></div></div>
</div><!--header-->
<div class="contents">

<p>Specialized socket using the TCP protocol.  
 <a href="classsf_1_1TcpSocket.html#details">More...</a></p>

<p><code>#include &lt;<a class="el" href="TcpSocket_8hpp_source.html">SFML/Network/TcpSocket.hpp</a>&gt;</code></p>
<div class="dynheader">
Inheritance diagram for sf::TcpSocket:</div>
<div class="dyncontent">
 <div class="center">
  <img src="classsf_1_1TcpSocket.png" usemap="#sf::TcpSocket_map" alt=""/>
  <map id="sf::TcpSocket_map" name="sf::TcpSocket_map">
<area href="classsf_1_1Socket.html" title="Base class for all the socket types." alt="sf::Socket" shape="rect" coords="0,56,105,80"/>
<area href="classsf_1_1NonCopyable.html" title="Utility class that makes any derived class non-copyable." alt="sf::NonCopyable" shape="rect" coords="0,0,105,24"/>
  </map>
</div></div>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pub-types" name="pub-types"></a>
Public Types</h2></td></tr>
<tr class="memitem:a51bf0fd51057b98a10fbb866246176dc"><td class="memItemLeft" align="right" valign="top">enum &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a> { <br />
&#160;&#160;<a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dca1de3a85bc56d3ae85b3d0f3cfd04ae90">Done</a>
, <a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dca8554848daae98f996e131bdeed076c09">NotReady</a>
, <a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dca181c163fad2eaea927185d127c392706">Partial</a>
, <a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dcab215141f756acdc23c67fad149710eb1">Disconnected</a>
, <br />
&#160;&#160;<a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dca1dc9854433a28c22e192721179a2df5d">Error</a>
<br />
 }</td></tr>
<tr class="memdesc:a51bf0fd51057b98a10fbb866246176dc"><td class="mdescLeft">&#160;</td><td class="mdescRight">Status codes that may be returned by socket functions.  <a href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">More...</a><br /></td></tr>
<tr class="separator:a51bf0fd51057b98a10fbb866246176dc"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aa3e6c984bcb81a35234dcc9cc8369d75"><td class="memItemLeft" align="right" valign="top">enum &#160;</td><td class="memItemRight" valign="bottom">{ <a class="el" href="classsf_1_1Socket.html#aa3e6c984bcb81a35234dcc9cc8369d75a5a3c30fd128895403afc11076f461b19">AnyPort</a> = 0
 }</td></tr>
<tr class="memdesc:aa3e6c984bcb81a35234dcc9cc8369d75"><td class="mdescLeft">&#160;</td><td class="mdescRight">Some special values used by sockets.  <a href="classsf_1_1Socket.html#aa3e6c984bcb81a35234dcc9cc8369d75">More...</a><br /></td></tr>
<tr class="separator:aa3e6c984bcb81a35234dcc9cc8369d75"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pub-methods" name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:a62a9bf81fd7f15fedb29fd1348483236"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1TcpSocket.html#a62a9bf81fd7f15fedb29fd1348483236">TcpSocket</a> ()</td></tr>
<tr class="memdesc:a62a9bf81fd7f15fedb29fd1348483236"><td class="mdescLeft">&#160;</td><td class="mdescRight">Default constructor.  <br /></td></tr>
<tr class="separator:a62a9bf81fd7f15fedb29fd1348483236"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a98e45f0f49af1fd99216b9195e86d86b"><td class="memItemLeft" align="right" valign="top">unsigned short&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1TcpSocket.html#a98e45f0f49af1fd99216b9195e86d86b">getLocalPort</a> () const</td></tr>
<tr class="memdesc:a98e45f0f49af1fd99216b9195e86d86b"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get the port to which the socket is bound locally.  <br /></td></tr>
<tr class="separator:a98e45f0f49af1fd99216b9195e86d86b"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aa8579c203b1fd21beb74d7f76444a94c"><td class="memItemLeft" align="right" valign="top"><a class="el" href="classsf_1_1IpAddress.html">IpAddress</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1TcpSocket.html#aa8579c203b1fd21beb74d7f76444a94c">getRemoteAddress</a> () const</td></tr>
<tr class="memdesc:aa8579c203b1fd21beb74d7f76444a94c"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get the address of the connected peer.  <br /></td></tr>
<tr class="separator:aa8579c203b1fd21beb74d7f76444a94c"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a93bced0afd4b1c60797a85725be04951"><td class="memItemLeft" align="right" valign="top">unsigned short&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1TcpSocket.html#a93bced0afd4b1c60797a85725be04951">getRemotePort</a> () const</td></tr>
<tr class="memdesc:a93bced0afd4b1c60797a85725be04951"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get the port of the connected peer to which the socket is connected.  <br /></td></tr>
<tr class="separator:a93bced0afd4b1c60797a85725be04951"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a68cd42d5ab70ab54b16787f555951c40"><td class="memItemLeft" align="right" valign="top"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1TcpSocket.html#a68cd42d5ab70ab54b16787f555951c40">connect</a> (const <a class="el" href="classsf_1_1IpAddress.html">IpAddress</a> &amp;remoteAddress, unsigned short remotePort, <a class="el" href="classsf_1_1Time.html">Time</a> timeout=<a class="el" href="classsf_1_1Time.html#a8db127b632fa8da21550e7282af11fa0">Time::Zero</a>)</td></tr>
<tr class="memdesc:a68cd42d5ab70ab54b16787f555951c40"><td class="mdescLeft">&#160;</td><td class="mdescRight">Connect the socket to a remote peer.  <br /></td></tr>
<tr class="separator:a68cd42d5ab70ab54b16787f555951c40"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ac18f518a9be3d6be5e74b9404c253c1e"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1TcpSocket.html#ac18f518a9be3d6be5e74b9404c253c1e">disconnect</a> ()</td></tr>
<tr class="memdesc:ac18f518a9be3d6be5e74b9404c253c1e"><td class="mdescLeft">&#160;</td><td class="mdescRight">Disconnect the socket from its remote peer.  <br /></td></tr>
<tr class="separator:ac18f518a9be3d6be5e74b9404c253c1e"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:affce26ab3bcc4f5b9269dad79db544c0"><td class="memItemLeft" align="right" valign="top"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1TcpSocket.html#affce26ab3bcc4f5b9269dad79db544c0">send</a> (const void *data, std::size_t size)</td></tr>
<tr class="memdesc:affce26ab3bcc4f5b9269dad79db544c0"><td class="mdescLeft">&#160;</td><td class="mdescRight">Send raw data to the remote peer.  <br /></td></tr>
<tr class="separator:affce26ab3bcc4f5b9269dad79db544c0"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a31f5b280126a96c6f3ad430f4cbcb54d"><td class="memItemLeft" align="right" valign="top"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1TcpSocket.html#a31f5b280126a96c6f3ad430f4cbcb54d">send</a> (const void *data, std::size_t size, std::size_t &amp;sent)</td></tr>
<tr class="memdesc:a31f5b280126a96c6f3ad430f4cbcb54d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Send raw data to the remote peer.  <br /></td></tr>
<tr class="separator:a31f5b280126a96c6f3ad430f4cbcb54d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a90ce50811ea61d4f00efc62bb99ae1af"><td class="memItemLeft" align="right" valign="top"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1TcpSocket.html#a90ce50811ea61d4f00efc62bb99ae1af">receive</a> (void *data, std::size_t size, std::size_t &amp;received)</td></tr>
<tr class="memdesc:a90ce50811ea61d4f00efc62bb99ae1af"><td class="mdescLeft">&#160;</td><td class="mdescRight">Receive raw data from the remote peer.  <br /></td></tr>
<tr class="separator:a90ce50811ea61d4f00efc62bb99ae1af"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a0f8276e2b1c75aac4a7b0a707b250f44"><td class="memItemLeft" align="right" valign="top"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1TcpSocket.html#a0f8276e2b1c75aac4a7b0a707b250f44">send</a> (<a class="el" href="classsf_1_1Packet.html">Packet</a> &amp;packet)</td></tr>
<tr class="memdesc:a0f8276e2b1c75aac4a7b0a707b250f44"><td class="mdescLeft">&#160;</td><td class="mdescRight">Send a formatted packet of data to the remote peer.  <br /></td></tr>
<tr class="separator:a0f8276e2b1c75aac4a7b0a707b250f44"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aa655352609bc9804f2baa020df3e7331"><td class="memItemLeft" align="right" valign="top"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1TcpSocket.html#aa655352609bc9804f2baa020df3e7331">receive</a> (<a class="el" href="classsf_1_1Packet.html">Packet</a> &amp;packet)</td></tr>
<tr class="memdesc:aa655352609bc9804f2baa020df3e7331"><td class="mdescLeft">&#160;</td><td class="mdescRight">Receive a formatted packet of data from the remote peer.  <br /></td></tr>
<tr class="separator:aa655352609bc9804f2baa020df3e7331"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a165fc1423e281ea2714c70303d3a9782"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Socket.html#a165fc1423e281ea2714c70303d3a9782">setBlocking</a> (bool blocking)</td></tr>
<tr class="memdesc:a165fc1423e281ea2714c70303d3a9782"><td class="mdescLeft">&#160;</td><td class="mdescRight">Set the blocking state of the socket.  <br /></td></tr>
<tr class="separator:a165fc1423e281ea2714c70303d3a9782"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ab1ceca9ac114b8baeeda3b34a0aca468"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Socket.html#ab1ceca9ac114b8baeeda3b34a0aca468">isBlocking</a> () const</td></tr>
<tr class="memdesc:ab1ceca9ac114b8baeeda3b34a0aca468"><td class="mdescLeft">&#160;</td><td class="mdescRight">Tell whether the socket is in blocking or non-blocking mode.  <br /></td></tr>
<tr class="separator:ab1ceca9ac114b8baeeda3b34a0aca468"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pro-types" name="pro-types"></a>
Protected Types</h2></td></tr>
<tr class="memitem:a5d3ff44e56e68f02816bb0fabc34adf8"><td class="memItemLeft" align="right" valign="top">enum &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Socket.html#a5d3ff44e56e68f02816bb0fabc34adf8">Type</a> { <a class="el" href="classsf_1_1Socket.html#a5d3ff44e56e68f02816bb0fabc34adf8acc02e97e90234b957eaad4dff7f22214">Tcp</a>
, <a class="el" href="classsf_1_1Socket.html#a5d3ff44e56e68f02816bb0fabc34adf8a6ebf3094830db4820191a327f3cc6ce2">Udp</a>
 }</td></tr>
<tr class="memdesc:a5d3ff44e56e68f02816bb0fabc34adf8"><td class="mdescLeft">&#160;</td><td class="mdescRight">Types of protocols that the socket can use.  <a href="classsf_1_1Socket.html#a5d3ff44e56e68f02816bb0fabc34adf8">More...</a><br /></td></tr>
<tr class="separator:a5d3ff44e56e68f02816bb0fabc34adf8"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pro-methods" name="pro-methods"></a>
Protected Member Functions</h2></td></tr>
<tr class="memitem:a675457784284ae2f5640bbbe16729393"><td class="memItemLeft" align="right" valign="top">SocketHandle&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Socket.html#a675457784284ae2f5640bbbe16729393">getHandle</a> () const</td></tr>
<tr class="memdesc:a675457784284ae2f5640bbbe16729393"><td class="mdescLeft">&#160;</td><td class="mdescRight">Return the internal handle of the socket.  <br /></td></tr>
<tr class="separator:a675457784284ae2f5640bbbe16729393"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aafbe140f4b1921e0d19e88cf7a61dcbc"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Socket.html#aafbe140f4b1921e0d19e88cf7a61dcbc">create</a> ()</td></tr>
<tr class="memdesc:aafbe140f4b1921e0d19e88cf7a61dcbc"><td class="mdescLeft">&#160;</td><td class="mdescRight">Create the internal representation of the socket.  <br /></td></tr>
<tr class="separator:aafbe140f4b1921e0d19e88cf7a61dcbc"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:af1dd898f7aa3ead7ff7b2d1c20e97781"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Socket.html#af1dd898f7aa3ead7ff7b2d1c20e97781">create</a> (SocketHandle handle)</td></tr>
<tr class="memdesc:af1dd898f7aa3ead7ff7b2d1c20e97781"><td class="mdescLeft">&#160;</td><td class="mdescRight">Create the internal representation of the socket from a socket handle.  <br /></td></tr>
<tr class="separator:af1dd898f7aa3ead7ff7b2d1c20e97781"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a71f2f5c2aa99e01cafe824fee4c573be"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Socket.html#a71f2f5c2aa99e01cafe824fee4c573be">close</a> ()</td></tr>
<tr class="memdesc:a71f2f5c2aa99e01cafe824fee4c573be"><td class="mdescLeft">&#160;</td><td class="mdescRight">Close the socket gracefully.  <br /></td></tr>
<tr class="separator:a71f2f5c2aa99e01cafe824fee4c573be"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="friends" name="friends"></a>
Friends</h2></td></tr>
<tr class="memitem:a2b2dd140834917bd44b512236bddea7c"><td class="memItemLeft" align="right" valign="top">class&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1TcpSocket.html#a2b2dd140834917bd44b512236bddea7c">TcpListener</a></td></tr>
<tr class="separator:a2b2dd140834917bd44b512236bddea7c"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Specialized socket using the TCP protocol. </p>
<p>TCP is a connected protocol, which means that a TCP socket can only communicate with the host it is connected to.</p>
<p>It can't send or receive anything if it is not connected.</p>
<p>The TCP protocol is reliable but adds a slight overhead. It ensures that your data will always be received in order and without errors (no data corrupted, lost or duplicated).</p>
<p>When a socket is connected to a remote host, you can retrieve informations about this host with the getRemoteAddress and getRemotePort functions. You can also get the local port to which the socket is bound (which is automatically chosen when the socket is connected), with the getLocalPort function.</p>
<p>Sending and receiving data can use either the low-level or the high-level functions. The low-level functions process a raw sequence of bytes, and cannot ensure that one call to Send will exactly match one call to Receive at the other end of the socket.</p>
<p>The high-level interface uses packets (see <a class="el" href="classsf_1_1Packet.html" title="Utility class to build blocks of data to transfer over the network.">sf::Packet</a>), which are easier to use and provide more safety regarding the data that is exchanged. You can look at the <a class="el" href="classsf_1_1Packet.html" title="Utility class to build blocks of data to transfer over the network.">sf::Packet</a> class to get more details about how they work.</p>
<p>The socket is automatically disconnected when it is destroyed, but if you want to explicitly close the connection while the socket instance is still alive, you can call disconnect.</p>
<p>Usage example: </p><div class="fragment"><div class="line"><span class="comment">// ----- The client -----</span></div>
<div class="line"> </div>
<div class="line"><span class="comment">// Create a socket and connect it to 192.168.1.50 on port 55001</span></div>
<div class="line"><a class="code hl_class" href="classsf_1_1TcpSocket.html">sf::TcpSocket</a> socket;</div>
<div class="line">socket.<a class="code hl_function" href="classsf_1_1TcpSocket.html#a68cd42d5ab70ab54b16787f555951c40">connect</a>(<span class="stringliteral">&quot;192.168.1.50&quot;</span>, 55001);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Send a message to the connected host</span></div>
<div class="line">std::string message = <span class="stringliteral">&quot;Hi, I am a client&quot;</span>;</div>
<div class="line">socket.<a class="code hl_function" href="classsf_1_1TcpSocket.html#affce26ab3bcc4f5b9269dad79db544c0">send</a>(message.c_str(), message.size() + 1);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Receive an answer from the server</span></div>
<div class="line"><span class="keywordtype">char</span> buffer[1024];</div>
<div class="line">std::size_t received = 0;</div>
<div class="line">socket.<a class="code hl_function" href="classsf_1_1TcpSocket.html#a90ce50811ea61d4f00efc62bb99ae1af">receive</a>(buffer, <span class="keyword">sizeof</span>(buffer), received);</div>
<div class="line">std::cout &lt;&lt; <span class="stringliteral">&quot;The server said: &quot;</span> &lt;&lt; buffer &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line"><span class="comment">// ----- The server -----</span></div>
<div class="line"> </div>
<div class="line"><span class="comment">// Create a listener to wait for incoming connections on port 55001</span></div>
<div class="line"><a class="code hl_class" href="classsf_1_1TcpListener.html">sf::TcpListener</a> listener;</div>
<div class="line">listener.<a class="code hl_function" href="classsf_1_1TcpListener.html#a9504758ea3570e62cb20b209c11776a1">listen</a>(55001);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Wait for a connection</span></div>
<div class="line"><a class="code hl_class" href="classsf_1_1TcpSocket.html">sf::TcpSocket</a> socket;</div>
<div class="line">listener.<a class="code hl_function" href="classsf_1_1TcpListener.html#ae2c83ce5a64d50b68180c46bef0a7346">accept</a>(socket);</div>
<div class="line">std::cout &lt;&lt; <span class="stringliteral">&quot;New client connected: &quot;</span> &lt;&lt; socket.<a class="code hl_function" href="classsf_1_1TcpSocket.html#aa8579c203b1fd21beb74d7f76444a94c">getRemoteAddress</a>() &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Receive a message from the client</span></div>
<div class="line"><span class="keywordtype">char</span> buffer[1024];</div>
<div class="line">std::size_t received = 0;</div>
<div class="line">socket.<a class="code hl_function" href="classsf_1_1TcpSocket.html#a90ce50811ea61d4f00efc62bb99ae1af">receive</a>(buffer, <span class="keyword">sizeof</span>(buffer), received);</div>
<div class="line">std::cout &lt;&lt; <span class="stringliteral">&quot;The client said: &quot;</span> &lt;&lt; buffer &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Send an answer</span></div>
<div class="line">std::string message = <span class="stringliteral">&quot;Welcome, client&quot;</span>;</div>
<div class="line">socket.<a class="code hl_function" href="classsf_1_1TcpSocket.html#affce26ab3bcc4f5b9269dad79db544c0">send</a>(message.c_str(), message.size() + 1);</div>
<div class="ttc" id="aclasssf_1_1TcpListener_html"><div class="ttname"><a href="classsf_1_1TcpListener.html">sf::TcpListener</a></div><div class="ttdoc">Socket that listens to new TCP connections.</div><div class="ttdef"><b>Definition</b> <a href="TcpListener_8hpp_source.html#l00044">TcpListener.hpp:45</a></div></div>
<div class="ttc" id="aclasssf_1_1TcpListener_html_a9504758ea3570e62cb20b209c11776a1"><div class="ttname"><a href="classsf_1_1TcpListener.html#a9504758ea3570e62cb20b209c11776a1">sf::TcpListener::listen</a></div><div class="ttdeci">Status listen(unsigned short port, const IpAddress &amp;address=IpAddress::Any)</div><div class="ttdoc">Start listening for incoming connection attempts.</div></div>
<div class="ttc" id="aclasssf_1_1TcpListener_html_ae2c83ce5a64d50b68180c46bef0a7346"><div class="ttname"><a href="classsf_1_1TcpListener.html#ae2c83ce5a64d50b68180c46bef0a7346">sf::TcpListener::accept</a></div><div class="ttdeci">Status accept(TcpSocket &amp;socket)</div><div class="ttdoc">Accept a new connection.</div></div>
<div class="ttc" id="aclasssf_1_1TcpSocket_html"><div class="ttname"><a href="classsf_1_1TcpSocket.html">sf::TcpSocket</a></div><div class="ttdoc">Specialized socket using the TCP protocol.</div><div class="ttdef"><b>Definition</b> <a href="TcpSocket_8hpp_source.html#l00046">TcpSocket.hpp:47</a></div></div>
<div class="ttc" id="aclasssf_1_1TcpSocket_html_a68cd42d5ab70ab54b16787f555951c40"><div class="ttname"><a href="classsf_1_1TcpSocket.html#a68cd42d5ab70ab54b16787f555951c40">sf::TcpSocket::connect</a></div><div class="ttdeci">Status connect(const IpAddress &amp;remoteAddress, unsigned short remotePort, Time timeout=Time::Zero)</div><div class="ttdoc">Connect the socket to a remote peer.</div></div>
<div class="ttc" id="aclasssf_1_1TcpSocket_html_a90ce50811ea61d4f00efc62bb99ae1af"><div class="ttname"><a href="classsf_1_1TcpSocket.html#a90ce50811ea61d4f00efc62bb99ae1af">sf::TcpSocket::receive</a></div><div class="ttdeci">Status receive(void *data, std::size_t size, std::size_t &amp;received)</div><div class="ttdoc">Receive raw data from the remote peer.</div></div>
<div class="ttc" id="aclasssf_1_1TcpSocket_html_aa8579c203b1fd21beb74d7f76444a94c"><div class="ttname"><a href="classsf_1_1TcpSocket.html#aa8579c203b1fd21beb74d7f76444a94c">sf::TcpSocket::getRemoteAddress</a></div><div class="ttdeci">IpAddress getRemoteAddress() const</div><div class="ttdoc">Get the address of the connected peer.</div></div>
<div class="ttc" id="aclasssf_1_1TcpSocket_html_affce26ab3bcc4f5b9269dad79db544c0"><div class="ttname"><a href="classsf_1_1TcpSocket.html#affce26ab3bcc4f5b9269dad79db544c0">sf::TcpSocket::send</a></div><div class="ttdeci">Status send(const void *data, std::size_t size)</div><div class="ttdoc">Send raw data to the remote peer.</div></div>
</div><!-- fragment --><dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1Socket.html" title="Base class for all the socket types.">sf::Socket</a>, <a class="el" href="classsf_1_1UdpSocket.html" title="Specialized socket using the UDP protocol.">sf::UdpSocket</a>, <a class="el" href="classsf_1_1Packet.html" title="Utility class to build blocks of data to transfer over the network.">sf::Packet</a> </dd></dl>

<p class="definition">Definition at line <a class="el" href="TcpSocket_8hpp_source.html#l00046">46</a> of file <a class="el" href="TcpSocket_8hpp_source.html">TcpSocket.hpp</a>.</p>
</div><h2 class="groupheader">Member Enumeration Documentation</h2>
<a id="aa3e6c984bcb81a35234dcc9cc8369d75" name="aa3e6c984bcb81a35234dcc9cc8369d75"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aa3e6c984bcb81a35234dcc9cc8369d75">&#9670;&#160;</a></span>anonymous enum</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">anonymous enum</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inherited</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Some special values used by sockets. </p>
<table class="fieldtable">
<tr><th colspan="2">Enumerator</th></tr><tr><td class="fieldname"><a id="aa3e6c984bcb81a35234dcc9cc8369d75a5a3c30fd128895403afc11076f461b19" name="aa3e6c984bcb81a35234dcc9cc8369d75a5a3c30fd128895403afc11076f461b19"></a>AnyPort&#160;</td><td class="fielddoc"><p>Special value that tells the system to pick any available port. </p>
</td></tr>
</table>

<p class="definition">Definition at line <a class="el" href="Socket_8hpp_source.html#l00066">66</a> of file <a class="el" href="Socket_8hpp_source.html">Socket.hpp</a>.</p>

</div>
</div>
<a id="a51bf0fd51057b98a10fbb866246176dc" name="a51bf0fd51057b98a10fbb866246176dc"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a51bf0fd51057b98a10fbb866246176dc">&#9670;&#160;</a></span>Status</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">enum <a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">sf::Socket::Status</a></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inherited</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Status codes that may be returned by socket functions. </p>
<table class="fieldtable">
<tr><th colspan="2">Enumerator</th></tr><tr><td class="fieldname"><a id="a51bf0fd51057b98a10fbb866246176dca1de3a85bc56d3ae85b3d0f3cfd04ae90" name="a51bf0fd51057b98a10fbb866246176dca1de3a85bc56d3ae85b3d0f3cfd04ae90"></a>Done&#160;</td><td class="fielddoc"><p>The socket has sent / received the data. </p>
</td></tr>
<tr><td class="fieldname"><a id="a51bf0fd51057b98a10fbb866246176dca8554848daae98f996e131bdeed076c09" name="a51bf0fd51057b98a10fbb866246176dca8554848daae98f996e131bdeed076c09"></a>NotReady&#160;</td><td class="fielddoc"><p>The socket is not ready to send / receive data yet. </p>
</td></tr>
<tr><td class="fieldname"><a id="a51bf0fd51057b98a10fbb866246176dca181c163fad2eaea927185d127c392706" name="a51bf0fd51057b98a10fbb866246176dca181c163fad2eaea927185d127c392706"></a>Partial&#160;</td><td class="fielddoc"><p>The socket sent a part of the data. </p>
</td></tr>
<tr><td class="fieldname"><a id="a51bf0fd51057b98a10fbb866246176dcab215141f756acdc23c67fad149710eb1" name="a51bf0fd51057b98a10fbb866246176dcab215141f756acdc23c67fad149710eb1"></a>Disconnected&#160;</td><td class="fielddoc"><p>The TCP socket has been disconnected. </p>
</td></tr>
<tr><td class="fieldname"><a id="a51bf0fd51057b98a10fbb866246176dca1dc9854433a28c22e192721179a2df5d" name="a51bf0fd51057b98a10fbb866246176dca1dc9854433a28c22e192721179a2df5d"></a>Error&#160;</td><td class="fielddoc"><p>An unexpected error happened. </p>
</td></tr>
</table>

<p class="definition">Definition at line <a class="el" href="Socket_8hpp_source.html#l00053">53</a> of file <a class="el" href="Socket_8hpp_source.html">Socket.hpp</a>.</p>

</div>
</div>
<a id="a5d3ff44e56e68f02816bb0fabc34adf8" name="a5d3ff44e56e68f02816bb0fabc34adf8"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a5d3ff44e56e68f02816bb0fabc34adf8">&#9670;&#160;</a></span>Type</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">enum <a class="el" href="classsf_1_1Socket.html#a5d3ff44e56e68f02816bb0fabc34adf8">sf::Socket::Type</a></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">protected</span><span class="mlabel">inherited</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Types of protocols that the socket can use. </p>
<table class="fieldtable">
<tr><th colspan="2">Enumerator</th></tr><tr><td class="fieldname"><a id="a5d3ff44e56e68f02816bb0fabc34adf8acc02e97e90234b957eaad4dff7f22214" name="a5d3ff44e56e68f02816bb0fabc34adf8acc02e97e90234b957eaad4dff7f22214"></a>Tcp&#160;</td><td class="fielddoc"><p>TCP protocol. </p>
</td></tr>
<tr><td class="fieldname"><a id="a5d3ff44e56e68f02816bb0fabc34adf8a6ebf3094830db4820191a327f3cc6ce2" name="a5d3ff44e56e68f02816bb0fabc34adf8a6ebf3094830db4820191a327f3cc6ce2"></a>Udp&#160;</td><td class="fielddoc"><p>UDP protocol. </p>
</td></tr>
</table>

<p class="definition">Definition at line <a class="el" href="Socket_8hpp_source.html#l00114">114</a> of file <a class="el" href="Socket_8hpp_source.html">Socket.hpp</a>.</p>

</div>
</div>
<h2 class="groupheader">Constructor &amp; Destructor Documentation</h2>
<a id="a62a9bf81fd7f15fedb29fd1348483236" name="a62a9bf81fd7f15fedb29fd1348483236"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a62a9bf81fd7f15fedb29fd1348483236">&#9670;&#160;</a></span>TcpSocket()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">sf::TcpSocket::TcpSocket </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Default constructor. </p>

</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a id="a71f2f5c2aa99e01cafe824fee4c573be" name="a71f2f5c2aa99e01cafe824fee4c573be"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a71f2f5c2aa99e01cafe824fee4c573be">&#9670;&#160;</a></span>close()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void sf::Socket::close </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">protected</span><span class="mlabel">inherited</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Close the socket gracefully. </p>
<p>This function can only be accessed by derived classes. </p>

</div>
</div>
<a id="a68cd42d5ab70ab54b16787f555951c40" name="a68cd42d5ab70ab54b16787f555951c40"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a68cd42d5ab70ab54b16787f555951c40">&#9670;&#160;</a></span>connect()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a> sf::TcpSocket::connect </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="classsf_1_1IpAddress.html">IpAddress</a> &amp;&#160;</td>
          <td class="paramname"><em>remoteAddress</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">unsigned short&#160;</td>
          <td class="paramname"><em>remotePort</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="classsf_1_1Time.html">Time</a>&#160;</td>
          <td class="paramname"><em>timeout</em> = <code><a class="el" href="classsf_1_1Time.html#a8db127b632fa8da21550e7282af11fa0">Time::Zero</a></code>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Connect the socket to a remote peer. </p>
<p>In blocking mode, this function may take a while, especially if the remote peer is not reachable. The last parameter allows you to stop trying to connect after a given timeout. If the socket is already connected, the connection is forcibly disconnected before attempting to connect again.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">remoteAddress</td><td>Address of the remote peer </td></tr>
    <tr><td class="paramname">remotePort</td><td>Port of the remote peer </td></tr>
    <tr><td class="paramname">timeout</td><td>Optional maximum time to wait</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Status code</dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1TcpSocket.html#ac18f518a9be3d6be5e74b9404c253c1e" title="Disconnect the socket from its remote peer.">disconnect</a> </dd></dl>

</div>
</div>
<a id="aafbe140f4b1921e0d19e88cf7a61dcbc" name="aafbe140f4b1921e0d19e88cf7a61dcbc"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aafbe140f4b1921e0d19e88cf7a61dcbc">&#9670;&#160;</a></span>create() <span class="overload">[1/2]</span></h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void sf::Socket::create </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">protected</span><span class="mlabel">inherited</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Create the internal representation of the socket. </p>
<p>This function can only be accessed by derived classes. </p>

</div>
</div>
<a id="af1dd898f7aa3ead7ff7b2d1c20e97781" name="af1dd898f7aa3ead7ff7b2d1c20e97781"></a>
<h2 class="memtitle"><span class="permalink"><a href="#af1dd898f7aa3ead7ff7b2d1c20e97781">&#9670;&#160;</a></span>create() <span class="overload">[2/2]</span></h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void sf::Socket::create </td>
          <td>(</td>
          <td class="paramtype">SocketHandle&#160;</td>
          <td class="paramname"><em>handle</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">protected</span><span class="mlabel">inherited</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Create the internal representation of the socket from a socket handle. </p>
<p>This function can only be accessed by derived classes.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">handle</td><td>OS-specific handle of the socket to wrap </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="ac18f518a9be3d6be5e74b9404c253c1e" name="ac18f518a9be3d6be5e74b9404c253c1e"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ac18f518a9be3d6be5e74b9404c253c1e">&#9670;&#160;</a></span>disconnect()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void sf::TcpSocket::disconnect </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Disconnect the socket from its remote peer. </p>
<p>This function gracefully closes the connection. If the socket is not connected, this function has no effect.</p>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1TcpSocket.html#a68cd42d5ab70ab54b16787f555951c40" title="Connect the socket to a remote peer.">connect</a> </dd></dl>

</div>
</div>
<a id="a675457784284ae2f5640bbbe16729393" name="a675457784284ae2f5640bbbe16729393"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a675457784284ae2f5640bbbe16729393">&#9670;&#160;</a></span>getHandle()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">SocketHandle sf::Socket::getHandle </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td> const</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">protected</span><span class="mlabel">inherited</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Return the internal handle of the socket. </p>
<p>The returned handle may be invalid if the socket was not created yet (or already destroyed). This function can only be accessed by derived classes.</p>
<dl class="section return"><dt>Returns</dt><dd>The internal (OS-specific) handle of the socket </dd></dl>

</div>
</div>
<a id="a98e45f0f49af1fd99216b9195e86d86b" name="a98e45f0f49af1fd99216b9195e86d86b"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a98e45f0f49af1fd99216b9195e86d86b">&#9670;&#160;</a></span>getLocalPort()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">unsigned short sf::TcpSocket::getLocalPort </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td> const</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Get the port to which the socket is bound locally. </p>
<p>If the socket is not connected, this function returns 0.</p>
<dl class="section return"><dt>Returns</dt><dd>Port to which the socket is bound</dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1TcpSocket.html#a68cd42d5ab70ab54b16787f555951c40" title="Connect the socket to a remote peer.">connect</a>, <a class="el" href="classsf_1_1TcpSocket.html#a93bced0afd4b1c60797a85725be04951" title="Get the port of the connected peer to which the socket is connected.">getRemotePort</a> </dd></dl>

</div>
</div>
<a id="aa8579c203b1fd21beb74d7f76444a94c" name="aa8579c203b1fd21beb74d7f76444a94c"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aa8579c203b1fd21beb74d7f76444a94c">&#9670;&#160;</a></span>getRemoteAddress()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="classsf_1_1IpAddress.html">IpAddress</a> sf::TcpSocket::getRemoteAddress </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td> const</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Get the address of the connected peer. </p>
<p>If the socket is not connected, this function returns <a class="el" href="classsf_1_1IpAddress.html#a4619b4abbe3c8fef056e7299db967404" title="Value representing an empty/invalid address.">sf::IpAddress::None</a>.</p>
<dl class="section return"><dt>Returns</dt><dd>Address of the remote peer</dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1TcpSocket.html#a93bced0afd4b1c60797a85725be04951" title="Get the port of the connected peer to which the socket is connected.">getRemotePort</a> </dd></dl>

</div>
</div>
<a id="a93bced0afd4b1c60797a85725be04951" name="a93bced0afd4b1c60797a85725be04951"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a93bced0afd4b1c60797a85725be04951">&#9670;&#160;</a></span>getRemotePort()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">unsigned short sf::TcpSocket::getRemotePort </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td> const</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Get the port of the connected peer to which the socket is connected. </p>
<p>If the socket is not connected, this function returns 0.</p>
<dl class="section return"><dt>Returns</dt><dd>Remote port to which the socket is connected</dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1TcpSocket.html#aa8579c203b1fd21beb74d7f76444a94c" title="Get the address of the connected peer.">getRemoteAddress</a> </dd></dl>

</div>
</div>
<a id="ab1ceca9ac114b8baeeda3b34a0aca468" name="ab1ceca9ac114b8baeeda3b34a0aca468"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ab1ceca9ac114b8baeeda3b34a0aca468">&#9670;&#160;</a></span>isBlocking()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">bool sf::Socket::isBlocking </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td> const</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inherited</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Tell whether the socket is in blocking or non-blocking mode. </p>
<dl class="section return"><dt>Returns</dt><dd>True if the socket is blocking, false otherwise</dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1Socket.html#a165fc1423e281ea2714c70303d3a9782" title="Set the blocking state of the socket.">setBlocking</a> </dd></dl>

</div>
</div>
<a id="aa655352609bc9804f2baa020df3e7331" name="aa655352609bc9804f2baa020df3e7331"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aa655352609bc9804f2baa020df3e7331">&#9670;&#160;</a></span>receive() <span class="overload">[1/2]</span></h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a> sf::TcpSocket::receive </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="classsf_1_1Packet.html">Packet</a> &amp;&#160;</td>
          <td class="paramname"><em>packet</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Receive a formatted packet of data from the remote peer. </p>
<p>In blocking mode, this function will wait until the whole packet has been received. This function will fail if the socket is not connected.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">packet</td><td><a class="el" href="classsf_1_1Packet.html" title="Utility class to build blocks of data to transfer over the network.">Packet</a> to fill with the received data</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Status code</dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1TcpSocket.html#affce26ab3bcc4f5b9269dad79db544c0" title="Send raw data to the remote peer.">send</a> </dd></dl>

</div>
</div>
<a id="a90ce50811ea61d4f00efc62bb99ae1af" name="a90ce50811ea61d4f00efc62bb99ae1af"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a90ce50811ea61d4f00efc62bb99ae1af">&#9670;&#160;</a></span>receive() <span class="overload">[2/2]</span></h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a> sf::TcpSocket::receive </td>
          <td>(</td>
          <td class="paramtype">void *&#160;</td>
          <td class="paramname"><em>data</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">std::size_t&#160;</td>
          <td class="paramname"><em>size</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">std::size_t &amp;&#160;</td>
          <td class="paramname"><em>received</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Receive raw data from the remote peer. </p>
<p>In blocking mode, this function will wait until some bytes are actually received. This function will fail if the socket is not connected.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">data</td><td>Pointer to the array to fill with the received bytes </td></tr>
    <tr><td class="paramname">size</td><td>Maximum number of bytes that can be received </td></tr>
    <tr><td class="paramname">received</td><td>This variable is filled with the actual number of bytes received</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Status code</dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1TcpSocket.html#affce26ab3bcc4f5b9269dad79db544c0" title="Send raw data to the remote peer.">send</a> </dd></dl>

</div>
</div>
<a id="affce26ab3bcc4f5b9269dad79db544c0" name="affce26ab3bcc4f5b9269dad79db544c0"></a>
<h2 class="memtitle"><span class="permalink"><a href="#affce26ab3bcc4f5b9269dad79db544c0">&#9670;&#160;</a></span>send() <span class="overload">[1/3]</span></h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a> sf::TcpSocket::send </td>
          <td>(</td>
          <td class="paramtype">const void *&#160;</td>
          <td class="paramname"><em>data</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">std::size_t&#160;</td>
          <td class="paramname"><em>size</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Send raw data to the remote peer. </p>
<p>To be able to handle partial sends over non-blocking sockets, use the <a class="el" href="classsf_1_1TcpSocket.html#a31f5b280126a96c6f3ad430f4cbcb54d" title="Send raw data to the remote peer.">send(const void*, std::size_t, std::size_t&amp;)</a> overload instead. This function will fail if the socket is not connected.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">data</td><td>Pointer to the sequence of bytes to send </td></tr>
    <tr><td class="paramname">size</td><td>Number of bytes to send</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Status code</dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1TcpSocket.html#a90ce50811ea61d4f00efc62bb99ae1af" title="Receive raw data from the remote peer.">receive</a> </dd></dl>

</div>
</div>
<a id="a31f5b280126a96c6f3ad430f4cbcb54d" name="a31f5b280126a96c6f3ad430f4cbcb54d"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a31f5b280126a96c6f3ad430f4cbcb54d">&#9670;&#160;</a></span>send() <span class="overload">[2/3]</span></h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a> sf::TcpSocket::send </td>
          <td>(</td>
          <td class="paramtype">const void *&#160;</td>
          <td class="paramname"><em>data</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">std::size_t&#160;</td>
          <td class="paramname"><em>size</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">std::size_t &amp;&#160;</td>
          <td class="paramname"><em>sent</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Send raw data to the remote peer. </p>
<p>This function will fail if the socket is not connected.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">data</td><td>Pointer to the sequence of bytes to send </td></tr>
    <tr><td class="paramname">size</td><td>Number of bytes to send </td></tr>
    <tr><td class="paramname">sent</td><td>The number of bytes sent will be written here</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Status code</dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1TcpSocket.html#a90ce50811ea61d4f00efc62bb99ae1af" title="Receive raw data from the remote peer.">receive</a> </dd></dl>

</div>
</div>
<a id="a0f8276e2b1c75aac4a7b0a707b250f44" name="a0f8276e2b1c75aac4a7b0a707b250f44"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a0f8276e2b1c75aac4a7b0a707b250f44">&#9670;&#160;</a></span>send() <span class="overload">[3/3]</span></h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a> sf::TcpSocket::send </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="classsf_1_1Packet.html">Packet</a> &amp;&#160;</td>
          <td class="paramname"><em>packet</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Send a formatted packet of data to the remote peer. </p>
<p>In non-blocking mode, if this function returns <a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dca181c163fad2eaea927185d127c392706" title="The socket sent a part of the data.">sf::Socket::Partial</a>, you <em>must</em> retry sending the same unmodified packet before sending anything else in order to guarantee the packet arrives at the remote peer uncorrupted. This function will fail if the socket is not connected.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">packet</td><td><a class="el" href="classsf_1_1Packet.html" title="Utility class to build blocks of data to transfer over the network.">Packet</a> to send</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Status code</dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1TcpSocket.html#a90ce50811ea61d4f00efc62bb99ae1af" title="Receive raw data from the remote peer.">receive</a> </dd></dl>

</div>
</div>
<a id="a165fc1423e281ea2714c70303d3a9782" name="a165fc1423e281ea2714c70303d3a9782"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a165fc1423e281ea2714c70303d3a9782">&#9670;&#160;</a></span>setBlocking()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void sf::Socket::setBlocking </td>
          <td>(</td>
          <td class="paramtype">bool&#160;</td>
          <td class="paramname"><em>blocking</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inherited</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Set the blocking state of the socket. </p>
<p>In blocking mode, calls will not return until they have completed their task. For example, a call to Receive in blocking mode won't return until some data was actually received. In non-blocking mode, calls will always return immediately, using the return code to signal whether there was data available or not. By default, all sockets are blocking.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">blocking</td><td>True to set the socket as blocking, false for non-blocking</td></tr>
  </table>
  </dd>
</dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1Socket.html#ab1ceca9ac114b8baeeda3b34a0aca468" title="Tell whether the socket is in blocking or non-blocking mode.">isBlocking</a> </dd></dl>

</div>
</div>
<h2 class="groupheader">Friends And Related Symbol Documentation</h2>
<a id="a2b2dd140834917bd44b512236bddea7c" name="a2b2dd140834917bd44b512236bddea7c"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a2b2dd140834917bd44b512236bddea7c">&#9670;&#160;</a></span>TcpListener</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">friend class <a class="el" href="classsf_1_1TcpListener.html">TcpListener</a></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">friend</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p class="definition">Definition at line <a class="el" href="TcpSocket_8hpp_source.html#l00213">213</a> of file <a class="el" href="TcpSocket_8hpp_source.html">TcpSocket.hpp</a>.</p>

</div>
</div>
<hr/>The documentation for this class was generated from the following file:<ul>
<li><a class="el" href="TcpSocket_8hpp_source.html">TcpSocket.hpp</a></li>
</ul>
</div><!-- contents -->
        </div>
        <div id="footer-container">
            <div id="footer">
                SFML is licensed under the terms and conditions of the <a href="https://www.sfml-dev.org/license.php">zlib/png license</a>.<br>
                Copyright &copy; Laurent Gomila &nbsp;::&nbsp;
                Documentation generated by <a href="http://www.doxygen.org/" title="doxygen website">doxygen</a> &nbsp;::&nbsp;
            </div>
        </div>
    </body>
</html>
